package gbench.sandbox.nsql.mongo;

import static gbench.common.matlib.MatlibCanvas.println;

import org.junit.jupiter.api.Test;

import gbench.common.fs.XlsFile.SimpleExcel;
import gbench.common.matlib.data.DataReader.DFrame;
import gbench.common.matlib.rdd.BasePair;
import gbench.common.matlib.rdd.PVec;
import gbench.data.json.JSN;
import gbench.data.nosql.mongo.IMgClc;
import gbench.data.nosql.mongo.MgDataApp;
import gbench.data.nosql.mongo.MgClc;
import gbench.common.tree.LittleTree.IRecord;
import static gbench.data.nosql.mongo.SimpleMongo.*;
import static gbench.common.tree.LittleTree.IRecord.*;

/**
 * 
 * @author Administrator
 *
 */
public class JunitERP {

    @Test
    public void foo() {
        final var dataApp = MgDataApp.of("127.0.01", 27017, "erp");
        final IMgClc startup = MgClc.of("127.0.01", 27017, "local", "startup_log"); // 产品系列
        final IMgClc t_user = dataApp.get("t_user"); // 产品系列
        final var excel = SimpleExcel.of("F:/slicef/desktop/doc/国务院部委人物.xlsx");
        final var matrix = excel.collect(0, DFrame.dfmclc2);
        final var history = excel.collect(1, DFrame.dfmclc2);
        println(matrix);
        final var pvec = matrix.rowsS()
                .map(e -> BasePair.bp(e.str("name"), e.str("department") + "-" + e.str("title")))
                .collect(PVec.pvec2clc());
        pvec.groupByKey().foreach((id, bp) -> {
            t_user.add(REC("name", bp._1(), "titles", bp._2().toArray(), "history",
                    history.rowsS().toArray(IRecord[]::new)));
        });
        startup.records().forEach(e -> {
            final var t = JSN.pretty(D(e));
            System.out.println(t);
        });

    }

}
